<template>
  <div>
    <div style="margin-left: 1rem;margin-top: 1rem;">
      用户Id：
      <el-input v-model="biaodan.userId" style="width: 240px" />
      用户名：
      <el-input v-model="biaodan.userName" style="width: 240px" />
      <el-button type="primary" style="margin-left: 1rem;" @click="onSubmit">查询</el-button>
    </div>
    <div style="width: 98%; margin-left: 1rem; margin-top: 2rem;">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="Id" width="90" />
        <el-table-column prop="userName" label="用户名" width="160" />
        <el-table-column prop="realName" label="真实姓名" width="160" />
        <el-table-column prop="content" label="动态" width="600" />
        <el-table-column prop="createTime" label="创建时间" />
      </el-table>
    </div>
    <div style="margin-left: 1rem ;margin-top: 3rem;">
      <el-pagination v-model:current-page="biaodan.pageIndex" v-model:page-size="biaodan.pageSize"
        :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { subjectPage, type SubjectdaType } from '@/api/rizhi'
// 表单数据
const biaodan = ref({
  userId: null,
  userName: null,
  pageIndex: 1,
  pageSize: 10
})
// 搜索
const onSubmit = ()=>{
getList()
}
//表格
const tableData = ref<SubjectdaType[]>([])
function getList() {
  subjectPage(biaodan.value).then(res => {
    console.log(res, "subject");
    if (res.code === 1) {
      tableData.value = (res.response?.list as SubjectdaType[])
      total.value = (res.response?.total as number)
    }
  })
}
getList()
//页码
const total = ref(0)
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`)
  biaodan.value.pageSize = val;
  getList()
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`)
  biaodan.value.pageIndex = val;
  getList()
}
</script>